package com.lixin.demo.controller;

import com.lixin.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/order/create")
    public int create(
            @RequestParam("accountId") Long accountId,
            @RequestParam("productId") Long productId,
            @RequestParam("num") int num
    ) {
        try {
            int createOrderResult = orderService.createOrder(accountId, productId, num);
            return createOrderResult;
        } catch (Exception e) {
            return -1;
        }
    }

}
